<?php

namespace App\Admin\Controllers\Dedusting;

use App\Models\DedustingUser;
use App\Http\Controllers\Controller;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Callout;
use Illuminate\Support\Facades\DB;
use Dcat\Admin\Form;
use Dcat\Admin\Admin;
use Dcat\Admin\Show;
use Illuminate\Http\Request;
use App\Handlers\IotCardHandler;

class UserController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('用户列表')
            ->description('')
            ->body($this->grid());
    }

    protected function grid()
    {
        return new Grid(DedustingUser::with(['devices']), function (Grid $grid) {
            $grid->column('nickname', '昵称');
            $grid->column('mobile', '手机');
            $grid->column('is_admin', '全局查看')->switch();
            $grid->column('device.name', '设备');
            $grid->column('created_at', '注册日期');
            // $grid->column('updated_at', '修改时间');

            $grid->disableCreateButton();
            $grid->disableActions();
        });
    }

    public function update($id){
        return $this->form()->update($id);
    }
    public function store(){
        return $this->form()->store();
    }

    public function form(){
        return Form::make(new DedustingUser(), function (Form $form) {
            $form->switch('is_admin', '全局查看');
        });
    }

    public function destroy($id)
    {
        return $this->form()->destroy($id);
    }
}